<!DOCTYPE html>
<html>

<head>
	<meta charset="utf-8">
	<title>商品劵管理</title>
	<meta name="renderer" content="webkit">
	<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
	<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
	<meta name="apple-mobile-web-app-status-bar-style" content="black">
	<meta name="apple-mobile-web-app-capable" content="yes">
	<meta name="format-detection" content="telephone=no">
	<link rel="stylesheet" href="${s.base}/js/layui/css/layui.css" media="all" />
	<link rel="stylesheet" href="${s.base}/css/base/base.css" media="all" /></head>
<!--<style type="text/css">
	.layui-table tbody .layui-table-cell {
		height: auto;
		line-height: 88px;
	}
</style>-->
<body class="childrenBody">
<form class="layui-form">
	<blockquote class="layui-elem-quote quoteBox" id="tool">
		<div class="layui-inline">
			<label class="layui-input-inline">状态</label>
			<label class="layui-input-inline">
				<select name="status" id="status"></select>
			</label>
			<label class="layui-input-inline">姓名</label>
			<label class="layui-input-inline">
				<input type="text" class="layui-input"  style="width: 140px;" name="memberName" placeholder="请输入姓名" />
			</label>
			<label class="layui-input-inline">手机号</label>
			<label class="layui-input-inline">
				<input type="text" class="layui-input"  style="width: 140px;" name="memberPhone" placeholder="请输入手机号" />
			</label>
			<label class="layui-input-inline">卷标题</label>
			<label class="layui-input-inline">
				<input type="text" class="layui-input"  style="width: 140px;" name="itemName" placeholder="请输入卷标题" />
			</label>

			<a class="layui-btn search_btn" lay-submit="" lay-filter="seacherBtn">搜索</a>
			<a class="layui-btn layui-btn-normal countMoneyBtn" >入库</a>
			<a class="layui-btn layui-btn-normal commitMoneyBtn" >结算</a>
			<a class="layui-btn layui-btn-normal export_btn" >导出</a>
		</div>
	</blockquote>
	<table id="entityList" lay-filter="entityList"></table>
</form>

<script type="text/javascript" src="${s.base}/js/layui/layui.js"></script>
<script type="text/javascript" src="${s.base}/js/base/base.js"></script>
<script type="text/javascript">layui.use(['jquery', 'pageUtil', 'dialogUtil', 'table', 'dateUtil','fileUtil'],
    function() {
        var $ = layui.jquery,
            fileUtil = layui.fileUtil,
            dateUtil = layui.dateUtil,
            dialogUtil = layui.dialogUtil,
            table = layui.table,
            pageUtil = layui.pageUtil;
        var tableIns = null;
        pageUtil.initDict("shop_count_money_status,shop_order_coupon_status",
            function(dictData) {
                pageUtil.showDict($("#status"), pageUtil.aceeptDictContentList(dictData, "shop_order_coupon_status"), "请选择状态");
                var url = "/shopOrderCoupon/page";
                var cols = [{
                    type: 'checkbox',
                    fixed: 'left'
                },
				{
					type: 'numbers',
					title: '序号'
				},
				{
					field: 'memberName',
					title: '姓名',
					align: 'center'
				},
				{
					field: 'memberPhone',
					title: '手机号',
					align: 'center'
				},
				{
					field: 'itemName',
					title: '商品名称',
					align: 'center'
				},
				{field: 'image', title: '卷图片',align:'center', templet:function(d){
						return "<img lay-event ='showPicture'  src='"+d.image+"' style='width:auto; max-width: 96%; height: 90%;'/>";
					},width:100},
				{field: 'image', title: '卷链接',align:'center', templet:function(d){
                        return "<input value='"+window.location.protocol+"//"+window.location.host+d.image+"' />";
					},width:100},
				{field: 'qrImage', title: '卷码',align:'center',width:180},
				{
					field: 'price',
					title: '劵价格',
					align: 'center'
				},
				{
					field: 'brandName',
					title: '品牌名称',
					align: 'center'
				},
				{
					field: 'catName',
					title: '分类名称',
					align: 'center'
				},
				{field: 'status', title: '交易状态',align:'center', templet:function(d){
						if (d.status == "1") {
							return "未入库";
						} else if (d.status == "5") {
							return "已入库";
						} else if (d.status == "2") {
							return "下架";
						} else if (d.status == "3") {
							return "结算";
						} else if (d.status == "4") {
							return "纠纷";
						}
					},width:100},
				{field: 'issueStatus', title: '纠纷状态',align:'center', templet:function(d){
						if (d.issueStatus == "1") {
							return "无纠纷";
						} else if (d.issueStatus == "2") {
							return "纠纷中";
						} else if (d.issueStatus == "3") {
							return "申诉中";
						} else if (d.issueStatus == "4") {
							return "纠纷无效";
						} else if (d.issueStatus == "5") {
							return "纠纷有效";
						}
					},width:100},
				{field: 'brandId', title: '是否付款',align:'center', templet:function(d){
						return pageUtil.aceeptDictContentName(dictData,"shop_count_money_status",d.countMoneyStatus);
					}},
				{
					field: 'issueMessage',
					title: '纠纷原因',
					align: 'center'
				},
				{
					field: 'issueCoverMessage',
					title: '申诉原因',
					align: 'center'
				},
				{
					field: 'issueResultMessage',
					title: '纠纷结果',
					align: 'center'
				},
				{
					field: 'uploadTime',
					title: '上传时间',
					width: 190,
					align: 'center',
					templet: function(d) {
						return dateUtil.formatDate(new Date(d.createTime), "yyyy-MM-dd hh:mm:ss");
					}
				},
				{
					field: 'manageTime',
					title: '处理时间',
					width: 190,
					align: 'center',
					templet: function(d) {
						return dateUtil.formatDate(new Date(d.updateTime), "yyyy-MM-dd hh:mm:ss");
					}
				},
				{
					title: '操作',
					width: 280,
					align: "center",
					fixed: 'right',
					templet: function (d) {
						if (d.status == "1"){
                                return '<a class="layui-btn cy-btnbg-edit layui-btn-sm" lay-event="undercarriage"> 下架 </a>\
                    			<a class="layui-btn cy-btnbg-edit layui-btn-sm" lay-event="edit"> 结算 </a>\
                    			<a class="layui-btn cy-btnbg-edit layui-btn-sm layui-btn-disabled" > 纠纷 </a>\
                    			<a class="layui-btn cy-btnbg-edit layui-btn-sm layui-btn-disabled" > 申诉 </a>';
                            } else if (d.status == "5"){
                                return '<a class="layui-btn cy-btnbg-edit layui-btn-sm layui-btn-disabled" > 下架 </a>\
                    				<a class="layui-btn cy-btnbg-edit layui-btn-sm" lay-event="edit"> 结算 </a>\
                    				<a class="layui-btn cy-btnbg-edit layui-btn-sm layui-btn-disabled" > 纠纷 </a>\
                    				<a class="layui-btn cy-btnbg-edit layui-btn-sm layui-btn-disabled" > 申诉 </a>';
                            }else if(d.status == "2") {
                                return '<a class="layui-btn cy-btnbg-edit layui-btn-sm layui-btn-disabled" > 下架 </a>\
									<a class="layui-btn cy-btnbg-edit layui-btn-sm layui-btn-disabled" > 结算 </a>\
									<a class="layui-btn cy-btnbg-edit layui-btn-sm layui-btn-disabled" > 纠纷 </a>\
									<a class="layui-btn cy-btnbg-edit layui-btn-sm layui-btn-disabled" > 申诉 </a>';
                            }else {
                                // 判断纠纷
                                var issueStatus = d.issueStatus;
                                if (issueStatus == "1") {
                                    return '<a class="layui-btn cy-btnbg-edit layui-btn-sm layui-btn-disabled" > 下架 </a>\
                                    	<a class="layui-btn cy-btnbg-edit layui-btn-sm layui-btn-disabled" > 结算 </a>\
										<a class="layui-btn cy-btnbg-edit layui-btn-sm" lay-event="issueEdit"> 纠纷 </a>\
										<a class="layui-btn cy-btnbg-edit layui-btn-sm layui-btn-disabled" > 申诉 </a>';
                                }else if (issueStatus == "2") {
                                    return '<a class="layui-btn cy-btnbg-edit layui-btn-sm layui-btn-disabled" > 下架 </a>\
                                    	<a class="layui-btn cy-btnbg-edit layui-btn-sm layui-btn-disabled" > 结算 </a>\
										<a class="layui-btn cy-btnbg-edit layui-btn-sm layui-btn-disabled" > 纠纷 </a>\
										<a class="layui-btn cy-btnbg-edit layui-btn-sm layui-btn-disabled" > 申诉 </a>';
                                }else if (issueStatus == "3") {
                                    return '<a class="layui-btn cy-btnbg-edit layui-btn-sm layui-btn-disabled" > 下架 </a>\
                                    	<a class="layui-btn cy-btnbg-edit layui-btn-sm layui-btn-disabled" > 结算 </a>\
                                    	<a class="layui-btn cy-btnbg-edit layui-btn-sm layui-btn-disabled" > 纠纷 </a>\
										<a class="layui-btn cy-btnbg-edit layui-btn-sm " lay-event="complainEdit"> 申诉 </a>';
                                }else if (issueStatus == "4") {
                                    return '<a class="layui-btn cy-btnbg-edit layui-btn-sm layui-btn-disabled" > 下架 </a>\
                                    	<a class="layui-btn cy-btnbg-edit layui-btn-sm layui-btn-disabled" > 结算 </a>\
										<a class="layui-btn cy-btnbg-edit layui-btn-sm layui-btn-disabled" > 纠纷 </a>\
										<a class="layui-btn cy-btnbg-edit layui-btn-sm layui-btn-disabled" > 申诉 </a>';
                                }else if (issueStatus == "5") {
                                    return '<a class="layui-btn cy-btnbg-edit layui-btn-sm layui-btn-disabled" > 下架 </a>\
                                    	<a class="layui-btn cy-btnbg-edit layui-btn-sm layui-btn-disabled" > 结算 </a>\
										<a class="layui-btn cy-btnbg-edit layui-btn-sm layui-btn-disabled" > 纠纷 </a>\
										<a class="layui-btn cy-btnbg-edit layui-btn-sm layui-btn-disabled" > 申诉 </a>';
                                }
                            }
                        }
                    }];
                tableIns = pageUtil.initDate(cols, url, true);
            });

        // 入库
        $(".countMoneyBtn").click(function(){
            // 获取所有的ids
            var checkStatus = layui.table.checkStatus('entityList').data;

            if(checkStatus.length == 0){
                layer.alert("请选择至少一个商品卷！")
                return false;
            }

            var ids = [];
            var statusFlag = true;
            $.each(checkStatus,function(i,v){
                // 只能选择非入库的即状态为status为1的
				if (v.status != "1") {
				    statusFlag = false;
				}
                ids.push(v.id);
            });
            if (!statusFlag) {
                layer.alert("您只能选择未入库的商品卷！")
                return false;
			}
            var idsStr = ids.join(",");
            //console.log(ids.join(","));
            pageUtil.delete("是否确定入库？", "/shopOrderCoupon/stockIn", {ids:idsStr},
                function(data) {
                    tableIns.reload();
                });
        });

        $(".commitMoneyBtn").click(function(){
            // 获取所有的ids
            var checkStatus = layui.table.checkStatus('entityList').data;

            if(checkStatus.length == 0){
                layer.alert("请选择至少一个商品卷！")
                return false;
            }

            var ids = [];
            var statusFlag = true;
            $.each(checkStatus,function(i,v){
                // 下架的，已结算的，纠纷的都不可结算
                if (v.status == "1" || v.status == "2" || v.status == "3" || v.status == "4") {
                    statusFlag = false;
                }
                ids.push(v.id);
            });
            if (!statusFlag) {
                layer.alert("您只能选择已入库的商品卷进行结算！")
                return false;
            }
            var idsStr = ids.join(",");
            //console.log(ids.join(","));
            pageUtil.delete("是否确定结算？", "/shopOrderCoupon/updateStatusByIds", {ids:idsStr,"status":3},
                function(data) {
                    tableIns.reload();
                });
        });

		// 导出
		$(".export_btn").on("click",function(){
			window.location.href = "/shopOrderCoupon/export";
		});

        table.on('tool(entityList)',
            function(obj) {
                var layEvent = obj.event,
                    data = obj.data;
                if (layEvent === 'edit') {
                    // pageUtil.editPopup("编辑", "/shopOrderCoupon/getEntity?id=" + data.id);
                    pageUtil.delete("确定结算该项吗？", "/shopOrderCoupon/updateStatusById", {
                            "id": data.id,
							"status":3,
                            "_method": "POST"
                        },
                        function(data) {
                            tableIns.reload();
                        });
                }else if (layEvent === 'showPicture') {
                    fileUtil.imageSingleShow(data.image);
                }  else if(layEvent === 'undercarriage'){
                    pageUtil.delete("确定下架该项吗？", "/shopOrderCoupon/updateStatusById", {
                            "id": data.id,
                            "status":2,
                            "_method": "POST"
                        },
                        function(data) {
                            tableIns.reload();
                        });
				} else if(layEvent === 'issueEdit'){
                    // 需要一个下拉选择
                    var id = data.id;
                    var index = layer.open({
                        type: 1,
                        title:'纠纷',
                        area: ['400px', 'auto'], //宽高
                        btn:['确定','取消'],
                        content: '<div style="height: 195px;padding: 15px !important;">'+
                        '<form class="layui-form" action="">'+
                        '<div class="layui-form-item layui-form-text" >'+
                        ' <textarea id="issueMessage" style="width:369px;height: 135px;!important;"></textarea>'+
                        '</div>'+
                        '</form>'+
                        '</div>'
                        ,success:function(){
                            pageUtil.initDict("shop_order_issue_status",
                                function(dictData) {
                                    pageUtil.showDict($("#issueStatus"), pageUtil.aceeptDictContentList(dictData, "shop_order_issue_status"), "", "");
                                });
                        }
                        ,yes:function (){
                            var issueMessage = $("#issueMessage").val();
                            if(issueMessage == null || issueMessage == ""){
                                dialogUtil.alert("请填写纠纷原因");
                                return false;
							}
							if(issueMessage.length > 200){
								dialogUtil.alert("纠纷原因不能超过100个字");
								return false;
							}
                            var params={
                                "id":id,
                                "issueStatus":"2",
                                "issueMessage":issueMessage
							}
                            $.post("/shopOrderCoupon/updateIssueStatusById", params, function (result) {
                                layer.close(index);
                                if (result.code == "0") {
                                    //操作成功
                                    tableIns.reload();
                                } else {
                                    //操作失败
                                    dialogUtil.alert(result.msg);
                                }
                            }, "json");
                        }
                        ,btn2: function(index, layero){

                        }
                    });
                } else if (layEvent == "complainEdit"){
					// 需要一个下拉选择
					var id = data.id;
					var index = layer.open({
						type: 1,
						title:'纠纷',
						area: ['400px', 'auto'], //宽高
						btn:['确定','取消'],
						content: '<div style="height: 195px;padding: 15px !important;">'+
						'<form class="layui-form" action="">'+
						'<div class="layui-form-item layui-form-text" >'+
						'<div class="layui-input-line">'+
						'<select class="form-control" name="issueStatus" lay-verify="required" id="issueStatus"></select>'+
						'</div>'+
						'</div>'+
						'<div class="layui-form-item layui-form-text" >'+
						' <textarea id="issueMessage" style="width:369px;height: 135px;!important;"></textarea>'+
						'</div>'+
						'</form>'+
						'</div>'
						,success:function(){
							pageUtil.initDict("shop_order_issue_status",
									function(dictData) {
										pageUtil.showDict($("#issueStatus"), pageUtil.aceeptDictContentList(dictData, "shop_order_issue_status"), "", "");
									});
						}
						,yes:function (){
							var issueMessage = $("#issueMessage").val();
							var issueStatus = $("#issueStatus").val();
							if(issueMessage == null || issueMessage == ""){
								dialogUtil.alert("请填写纠纷原因");
								return false;
							}
							if(issueMessage.length > 200){
								dialogUtil.alert("纠纷原因不能超过100个字");
								return false;
							}
							var params={
								"id":id,
								"issueStatus":issueStatus,
								"issueResultMessage":issueMessage
							}
							$.post("/shopOrderCoupon/updateIssueStatusById", params, function (result) {
								layer.close(index);
								if (result.code == "0") {
									//操作成功
									tableIns.reload();
								} else {
									//操作失败
									dialogUtil.alert(result.msg);
								}
							}, "json");
						}
						,btn2: function(index, layero){

						}
					});

				}else if (layEvent === 'del') {
                    pageUtil.delete("确定删除该项吗？", "/shopOrderCoupon/delete", {
                            "id": data.id,
                            "_method": "DELETE"
                        },
                        function(data) {
                            tableIns.reload();
                        });
                }
            });
    })</script>
</body>

</html>